import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;



public class IO {

	public static boolean write(String filename,String Text)
	{
		try {
			FileOutputStream fos = new FileOutputStream(filename);
			DataOutputStream dos = new DataOutputStream(fos);
			dos.writeUTF(Text);
			dos.flush();
            dos.close();
            return true;
		} catch (FileNotFoundException e) {
			System.out.println("Cannot write on file:" + filename);
			return false;
		} catch (IOException e) {
			System.out.println("Cannot write on file:" + filename);
			return false;
		}
		
		
	}

	public static String read(String filename)
	{
		try {
			FileInputStream fis = new FileInputStream(filename);
			DataInputStream dis = new DataInputStream(fis);
			return  dis.readLine();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			return "cannot read file";
		} catch (IOException e) {
			// TODO Auto-generated catch block
			return "cannot read file";
		}
	}
	
	public static boolean writeobj(String filename,Store store)
	{
		try {
			IOMaster.writeObject(filename, store);
			return true;
		} catch (FileNotFoundException e) {
			e.printStackTrace();
			return false;
		} catch (IOException e) {
			e.printStackTrace();
			return false;
		}
	}
	
	public static Store readobj(String filename)
	{
		Store store = new Store();
		try {
			store = IOMaster.readObject(filename);
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return store;
	}
	
	
}
